﻿using B.MES.FLH.WarehouseManagement.Application;
using B.MES.FLH.WarehouseManagement.Application.Dtos.IOWarehouserecord;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Standard;

namespace B.MES.FLH.WarehouseManagement.Controllers
{
    /// <summary>
    /// 出入库控制器
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class IOWareHouseController : ControllerBase
    {
        private readonly IService _service;
        public IOWareHouseController(IService service)
        {
            _service = service;
        }
        /// <summary>
        /// 编码生成器
        /// </summary>
        /// <param name="codeType"></param>
        /// <returns></returns>
        [HttpGet("GetCode")]
        public async Task<IActionResult> GetCode([FromQuery] string codeType)
        {
            try
            {
                var result = await _service.GetCode(codeType);
                return Ok(result);
            }
            catch (Exception ex)
            {
                return StatusCode(500, new ApiResult<string>
                {
                    Code = ApiCode.InternalError,
                    Message = $"获取编码失败: {ex.Message}"
                });
            }
        }
        /// <summary>
        /// 创建入库记录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("CreateIOWAREHOUSERECORDMODEL")]
        public ApiResult<int> CreateIOWAREHOUSERECORDMODEL(CreateIOWAREHOUSERECORDModelInput input)
        {
            return _service.CreateIOWAREHOUSERECORDMODEL(input);
        }
        /// <summary>
        /// 获取出入库记录
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        [HttpGet("GetIOWAREHOUSERECORDMODEL")]
        public ApiPaging<IOWAREHOUSERECORDModelOutput> GetIOWAREHOUSERECORDMODEL([FromQuery]PageIOWAREHOUSERECORD page)
        {
            return _service.GetIOWAREHOUSERECORDMODEL(page);
        }
        /// <summary>
        /// 删除出入库记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost("DeleteIOWAREHOUSERECORDMODEL")]
        public ApiResult<int> DeleteIOWAREHOUSERECORDMODEL(string id)
        {
            return _service.DeleteIOWAREHOUSERECORDMODEL(id);
        }
    }
}
